'use strict';

const { Model } = require('sequelize');

module.exports = (sequelize, DataTypes) => {
  class PresetFile extends Model {
    static associate(models) {
      // 定义关联
      PresetFile.belongsTo(models.User, { foreignKey: 'createdBy', as: 'Creator' });
    }
  }
  
  PresetFile.init({
    name: {
      type: DataTypes.STRING,
      allowNull: false
    },
    description: {
      type: DataTypes.TEXT,
      allowNull: true
    },
    filePath: {
      type: DataTypes.STRING,
      allowNull: false
    },
    fileType: {
      type: DataTypes.STRING,
      allowNull: false
    },
    size: {
      type: DataTypes.INTEGER,
      allowNull: true
    },
    mimeType: {
      type: DataTypes.STRING,
      allowNull: true
    },
    isActive: {
      type: DataTypes.BOOLEAN,
      defaultValue: true
    },
    createdBy: {
      type: DataTypes.INTEGER,
      allowNull: false,
      references: {
        model: 'users',
        key: 'id'
      }
    }
  }, {
    sequelize,
    modelName: 'PresetFile',
    tableName: 'preset_files',
    timestamps: true
  });
  
  return PresetFile;
}; 